package com.qingcheng.service.impl;

import com.qingcheng.dao.TbFreightTemplateMapper;
import com.qingcheng.pojo.config.FreightTemplate;
import com.qingcheng.pojo.config.TbFreightTemplate;
import com.qingcheng.service.TbFreightTemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.Page;
import com.qingcheng.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
*
* @author Simon
* @date 2020/08/08
*/
@Service
public class TbFreightTemplateServiceImpl implements TbFreightTemplateService {

    @Resource
    private TbFreightTemplateMapper tbFreightTemplateMapper;

    @Override
    public List<TbFreightTemplate> queryAll() {
        Example example = new Example(TbFreightTemplate.class);
        example.setOrderByClause("id DESC");
        List<TbFreightTemplate> tbFreightTemplate = tbFreightTemplateMapper.selectByExample(example);
            return tbFreightTemplate;
    }

    @Override
    public PageUtil<TbFreightTemplate> findListAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<TbFreightTemplate> pages = (Page<TbFreightTemplate>) tbFreightTemplateMapper.selectAll();
        PageUtil<TbFreightTemplate> pageUtil=new PageUtil<>();
        pageUtil.setRows(pages.getResult());
        pageUtil.setTotal(pages.getTotal());
        return pageUtil;
    }


    @Override
    public PageUtil<TbFreightTemplate> pageQueryByAll(Integer pageNum, Integer pageSize, TbFreightTemplate tbFreightTemplate) {

        Example example=new Example(TbFreightTemplate.class);
        Example.Criteria criteria = example.createCriteria();
        // TODO 待实现 重新实现判断参数

        //if(!StringUtils.isEmpty(brand.getId())){
        //    criteria.andEqualTo("id",brand.getId());
        //}
        //if(!StringUtils.isEmpty(brand.getName())){
        //   criteria.andLike("name",brand.getName());
        //}
        PageHelper.startPage(pageNum,pageSize);
        Page<TbFreightTemplate> pages = (Page<TbFreightTemplate>) tbFreightTemplateMapper.selectByExample(example);
        PageUtil<TbFreightTemplate> pageUtil=new PageUtil<>();
        pageUtil.setRows(pages.getResult());
        pageUtil.setTotal(pages.getTotal());
        return pageUtil;
     }


    @Override
    public boolean saveTbFreightTemplate(TbFreightTemplate tbFreightTemplate) {
        int insert = tbFreightTemplateMapper.insert(tbFreightTemplate);
        if(insert>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateTbFreightTemplate(TbFreightTemplate tbFreightTemplate) {
        int i = tbFreightTemplateMapper.updateByPrimaryKeySelective(tbFreightTemplate);
        if(i>0){
            return true;
        }
        return false;
    }


    @Override
    public boolean deleteById(Integer id) {
        int i = tbFreightTemplateMapper.deleteByPrimaryKey(id);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public TbFreightTemplate findById(Integer id) {
        TbFreightTemplate tbFreightTemplate = tbFreightTemplateMapper.selectByPrimaryKey(id);
        return tbFreightTemplate;
    }
}
